package com.vitabuybuy.tv.ui.home.live

import android.os.Bundle
import androidx.core.os.bundleOf
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
import com.library.common.base.BaseActivity
import com.library.common.base.MessageModel
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivitySearchLiveResultBinding
import com.vitabuybuy.tv.ui.home.live.viewmodel.LiveAreaViewModel
import kotlinx.android.synthetic.main.activity_live_zone.*

/**
 * 作者：SimGa
 * 日期：2021/1/9
 * 时间：16:23
 * 包名：com.vitabuybuy.tv.ui.home.live
 */
class SearchLiveResultActivity : BaseActivity<LiveAreaViewModel, ActivitySearchLiveResultBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_search_live_result

    private var hotkey: String? = null
    private var pageNumber = 1

    override fun onGetBundle(bundle: Bundle?) {
        super.onGetBundle(bundle)
        hotkey = bundle?.getString("hotkey")
    }


    override fun initView(savedInstanceState: Bundle?) {
        setTitle(hotkey!!)
        mBinding.apply {
            mViewModel = viewModel
        }
    }

    override fun observeData() {
        viewModel.getLiveList(-1,"viewer_quantity",-1,hotkey,pageNumber)
    }
    override fun eventHandling() {
        refresh.setOnRefreshListener(object : RefreshListenerAdapter() {
            override fun onLoadMore(refreshLayout: TwinklingRefreshLayout?) {
                pageNumber++
                viewModel.getLiveList(-1,"viewer_quantity",-1,hotkey,pageNumber)
            }

            override fun onRefresh(refreshLayout: TwinklingRefreshLayout?) {
                pageNumber = 1
                viewModel.getLiveList(-1,"viewer_quantity",-1,hotkey,pageNumber)
            }
        })
    }

    override fun handleEvent(msg: MessageModel) {
        super.handleEvent(msg)
        when (msg.code) {
            1 -> {
                refresh.onLoad(msg.arg1)
            }
            2 -> {

            }
        }
    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, hotkey: String?) {
            mContext.startActivity(
                bundleOf(Pair("hotkey", hotkey)),
                SearchLiveResultActivity::class.java
            )
        }
    }
}